home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / hsend.exe / BHSEND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-17  |  19.2 KB  |  778 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <io.h>
  4. #include <fcntl.h>
  5. #include <stat.h>
  6. #include <conio.h>
  7. #include <dir.h>
  8. #include <dos.h>
  9. #include <time.h>
  10. #include <async.h>
  11. #include <process.h>
  12.  
  13. #define HOST 1
  14. #define GUEST 0
  15. #define DATAFILE "CONFIGUR.DAT"
  16. #define OFFLINE (!(a_getmsr(P)&CRX) && !(bioskey(2)&64))
  17. #define TRY 3                    /* number of attempts to resend garbled data block */
  18. #define CRX 128                    /* carrier detect        */
  19. #define OKTS 1                    /* OK to send            */
  20. #define SFR 2                    /* send file request     */
  21. #define IFR 3                    /* initiate file receive */
  22. #define IFS 4                   /* initiate file send    */
  23. #define DF 5                    /* delete file           */
  24. #define RP 6                    /* request password        */
  25. #define SP 7                    /* sending password        */
  26. #define EM 8                    /* error message         */
  27. #define EOC 9                    /* end of call            */
  28. #define ACK 10                    /* acknowledgement        */
  29. #define NAK 11                    /* not acknowledged        */
  30. #define SDB 12                    /* sending data block    */
  31.  
  32. void host_mode(void),beep(int,int),copyright(void),report(char *);
  33. void delete_files(char *,int),error_message(char *),end_of_call(void);
  34. void empty_box(int,int,int,int),tsr(unsigned int),b_sleep(int);
  35. void interrupt background_host_mode(void);
  36. void interrupt call(void);
  37. int initiate_file_send(char *,char *),send_file_request(unsigned char *,int);
  38. int init_modem(void),load_data(void),break_handler(void);
  39. int password_check(void),scb(int,int,unsigned char *),rcb(int,unsigned char *),agetc(void);
  40. int cmd_mode(int),seperate(char *,char *,char*,char);
  41. int create_local_file(char *),rdb(int,unsigned char *);
  42. char *eight_plus_three(char *,char);
  43.  
  44. int WAITING,BAUD,COMM,RINGS,SCREENFLAG,LOGFILEFLAG,FLAGFILEFLAG;
  45. int I,C,TIMEOUT=180,IN_USE=0;
  46. long TIMER;
  47. char LOGFILE[61],FLAGFILE[61],PASSWORD[13];
  48. unsigned char TEMP[518],BUF[518],IOBUF[518];
  49. char SOURCE_PATHNAME[200],DEST_PATHNAME[200],FROM[200],TO[200];
  50. char PATH[100],PATHNAME[116];
  51. char SCREEN_BUFFER[644],RESTORE_BUFFER[644];
  52. struct ffblk F,F1;
  53.  
  54. ASYNC *P=NULL;
  55.  
  56. struct address{
  57.     char far *p;};
  58.  
  59. struct address far *int63=(struct address far *) 252;
  60. struct address far *int62=(struct address far *) 248;
  61. struct address far *int28h=(struct address far *) 160;
  62.  
  63. struct tm *PTR;
  64. time_t LT;
  65.  
  66. main(argc)
  67. int argc;
  68. {
  69. load_data();
  70.  
  71. if(argc>1){
  72.     cprintf("\n\rUsage:  bhsend <no arguments>    Run in background host mode\n\r");
  73.     beep(3,400);
  74.     exit(1);}
  75.  
  76.  
  77. if(int63->p!=int62->p){
  78.     cprintf("\n\rBHSEND is already running.\n\r");
  79.     exit(1);}
  80.  
  81.  
  82. TIMEOUT*=2;                        /* host waits longer */
  83. copyright();
  84.  
  85. if(!init_modem()){
  86.     gotoxy(1,21);
  87.     textcolor(LIGHTGRAY);
  88.     cprintf("\n\rCOMM device did not respond.  Check settings with CONFIGUR.\n\r");
  89.     beep(3,400);
  90.     exit(1);}
  91.  
  92.  
  93. gotoxy(22,12);
  94. textcolor(LIGHTCYAN|BLINK);
  95. cprintf("Background program is running, please wait");
  96. gettext(20,8,65,14,SCREEN_BUFFER);
  97. gotoxy(22,12);
  98. cprintf("                                          ");
  99. gotoxy(1,24);
  100. textcolor(LIGHTGRAY);
  101. cprintf("HSEND background mode has been loaded into memory.");
  102. int62->p=int28h->p;                         /* move the old vector   */
  103. int28h->p=(char far *)background_host_mode;            /* put in the new vector */
  104. tsr(5473);
  105. }
  106.  
  107.  
  108. void interrupt background_host_mode(void)                            /* TSR enters here */
  109. {
  110. geninterrupt(62);
  111.  
  112. if(!OFFLINE && !IN_USE){
  113.     IN_USE++;
  114.     gettext(20,8,65,14,RESTORE_BUFFER);
  115.     puttext(20,8,65,14,SCREEN_BUFFER);
  116.     LT=time(NULL);
  117.     PTR=localtime(<);
  118.     strcpy(TEMP,"On-line: ");
  119.     strcat(TEMP,asctime(PTR));
  120.     report(TEMP);
  121.     if(password_check()) while(cmd_mode(1));
  122.     LT=time(NULL);
  123.     PTR=localtime(<);
  124.     strcpy(TEMP,"Modem Reset: ");
  125.     strcat(TEMP,asctime(PTR));
  126.     report(TEMP);
  127.     report("---------------------------------------------------------------------------\n\r");
  128.     a_setmcr(P,0);                    /* hang up */                        /* set DTR and RTS high                    */
  129.     b_sleep(2);
  130.     a_setmcr(P,MCR_DTR+MCR_RTS);            /* set DTR and RTS high                    */
  131.     b_sleep(1);
  132.     a_puts("+++",P);
  133.     b_sleep(2);
  134.     a_puts("\n\rATZ\n\r",P);
  135.     b_sleep(2);
  136.     strcpy(TEMP,"AT S0=1 V0 &D3\n\r");
  137.     TEMP[6]=RINGS+48;                            /* set correct value for S0 */
  138.     a_puts(TEMP,P);
  139.     C=a_icount(P);
  140.     for(I=0;I<C;I++)
  141.         a_getc(P);
  142.     while(!OFFLINE);                            /* wait here */
  143.     while(bioskey(1)) bioskey(0);                    /* empty keystroke buffer */
  144.     puttext(20,8,65,14,RESTORE_BUFFER);
  145.     IN_USE=0;
  146.     }
  147.  
  148.  
  149. }                                        /* TSR exits until next int28H call */
  150.  
  151.  
  152. int cmd_mode(host_flag)                            /* return 0 at end of sesssion      */
  153. {
  154.  
  155. for(;;){
  156.  if(host_flag){
  157.     if(!scb(OKTS,0,NULL)){                        /* OK to send                       */
  158.         report("ERROR- OKTS transmission not acknowledged");
  159.         return 0;}}
  160.  
  161.  
  162.  do{                                            /* receiving command                */
  163.     if(OFFLINE){
  164.         report("DATA CONNECTION LOST");
  165.         return 0;}
  166.     C=rcb(0,BUF);
  167.     }while(!C);
  168.  
  169. switch(C){
  170.  
  171.     case OKTS: return -1;
  172.  
  173.     case SFR: send_file_request(BUF,0);
  174.             break;
  175.  
  176.     case IFR: create_local_file(BUF);
  177.             break;
  178.  
  179.     case DF:  delete_files(BUF,HOST);
  180.             break;
  181.  
  182.     case EM:  error_message(BUF);
  183.             break;
  184.  
  185.     case EOC: report("Transmission terminated normally");
  186.             return 0;
  187.  
  188.     default:  report("cmd_mode() default");
  189.             if(!host_flag) return -1;}            /* switch back to active mode */
  190.  
  191.  
  192. } /* endless loop */
  193. }
  194.  
  195.  
  196. void report(message)
  197. char *message;
  198. {
  199. int fp;
  200.  
  201. if(!LOGFILEFLAG) return;
  202.  
  203. if((fp=_open(LOGFILE,O_WRONLY|O_APPEND))==-1){
  204.     if((fp=open(LOGFILE,O_CREAT,S_IWRITE))==-1){
  205.          putch('!');
  206.          return;}}
  207.  
  208. if(write(fp,message,strlen(message))<0) beep(3,300);
  209. write(fp,"\n\r",2);
  210. close(fp);
  211. }
  212.  
  213.  
  214. int init_modem(void)
  215. {
  216. int x;
  217.  
  218. if(P) a_close(P,0);
  219. P=a_open(COMM,BAUD,0,8,1,1040,1040);                /* open at no parity,8 dbits, 1 sbit 1K input ,1k output buffer */
  220. a_setmcr(P,MCR_DTR+MCR_RTS);                        /* set DTR and RTS high                    */
  221. b_sleep(2);
  222. a_iflush(P);                                /* clear input buffer                      */
  223. b_sleep(1);
  224. a_puts("+++",P);
  225. b_sleep(2);
  226. a_puts("\n\rATZ\n\r",P);
  227. b_sleep(2);
  228. strcpy(TEMP,"AT s0=1 V0\n\r");
  229. TEMP[6]=RINGS+48;                            /* set correct value for S0 */
  230. a_puts(TEMP,P);
  231. a_waitquiet(P,18,72,1);                            /* wait for a reply                        */
  232. x=a_icount(P);
  233. while(a_icount(P)) a_getc(P);                        /* clear input buffer                      */
  234. return x;                                        /* return # of characters in reply         */
  235. }                                            /* 0 return value denotes no modem present */
  236.  
  237.  
  238. int agetc(void)                                /* returns 0 if error occurs     */
  239. {
  240.  
  241. TIMER=biostime(0,0);
  242. do{
  243.     if(OFFLINE) return -1;                        /* no carrier                    */
  244.     if(a_icount(P)) return a_getc(P);
  245.     }while(biostime(0,0)-TIMER<TIMEOUT);
  246.  
  247. report("Timeout");
  248. return -2;
  249. }
  250.  
  251.  
  252. int password_check(void)                            /* return 1 if password is verified */
  253. {
  254. b_sleep(3);
  255. if(!scb(RP,0,NULL)){
  256.     report("Caller could not verify Requesting Password transmission");
  257.     return 0;}
  258. if(!rcb(SP,BUF)){
  259.     report("Caller did not sent password");
  260.     return 0;}
  261. if(!strcmp(BUF,PASSWORD)) return 1;                /* correct password received */
  262. report("Incorrect password received.");
  263. return 0;
  264. }
  265.  
  266.  
  267. int scb(cmd,blklen,blk)                            /* send command block, returns 1 if acknowledged */
  268. int cmd;                                        /* #defined command code            */
  269. int blklen;                                    /* number of data characters        */
  270. unsigned char *blk;                                /* 0 to 512 data characters         */
  271. {                                            /* returns value of carrier detect  */
  272. int i,try,reply;
  273. unsigned long cksum;
  274.  
  275. while(a_icount(P)) a_getc(P);                        /* clear input buffer     */
  276. IOBUF[3]=cmd;                                    /* command code           */
  277. IOBUF[4]=blklen/255;                                /* # of data chars hibyte */
  278. IOBUF[5]=blklen-(IOBUF[4]*255);                        /* # of data chars lobyte */
  279.  
  280. if(blklen){                                    /* if there are data characters */
  281.     for(i=0;i<blklen;i++)                        /* copy them into buf           */
  282.         IOBUF[i+6]=blk[i];}
  283.  
  284. for(i=3,cksum=0;i<blklen+6;i++)                    /* add to create checksum */
  285.     cksum+=IOBUF[i];
  286.  
  287. IOBUF[0]=cksum/65025;                                /* checksum hibyte  */
  288. cksum-=(long)IOBUF[0]*65025;
  289. IOBUF[1]=cksum/255;                                /* checksum midbyte */
  290. IOBUF[2]=cksum-(long)(IOBUF[1]*255);                    /* checksum lobyte  */
  291.  
  292. for(try=0;try<TRY;try++){
  293.     for(i=0;i<blklen+6;i++)
  294.         a_putc(IOBUF[i],P);                        /* send the block   */
  295.     reply=agetc();
  296.     if(reply==ACK)    return 1;                        /* OK               */
  297.     if(reply==-1) return 0;                        /* no carrier       */
  298.     if(reply!=NAK)    while(a_icount(P)) a_getc(P);}    /* remove the trash */
  299.  
  300. return 0;
  301. }
  302.  
  303.  
  304. int rcb(cmd,blk)                                /* receive command block              */
  305. int cmd;                                        /* expected reply command             */
  306. unsigned char *blk;                                /* fills blk with data chars received */
  307. {                                            /* returns 0 if cannot verify block on TRY attempts */
  308. long cksum,tempsum;
  309. int i;
  310. int tmp,charcount;
  311.  
  312. for(i=0;i<6;i++){                                /* get first 6 characters         */
  313.     tmp=agetc();
  314.     if(tmp<0) return 0;
  315.     IOBUF[i]=tmp;}
  316.  
  317. charcount=(IOBUF[4]*255)+IOBUF[5];                    /* get remaining data characters  */
  318. if(charcount){
  319.     for(i=6;i<charcount+6;i++){
  320.         tmp=agetc();
  321.         if(tmp<0) return 0;                        /* no carrier or timeout          */
  322.         IOBUF[i]=tmp;
  323.         blk[i-6]=tmp;}}
  324.  
  325. for(tempsum=0,i=3;i<charcount+6;i++)                 /* create checksum of chars received */
  326.     tempsum+=IOBUF[i];
  327.  
  328. cksum=(long)IOBUF[0]*65025;                        /* create cheksum sent with data     */
  329. cksum+=(long)IOBUF[1]*255;
  330. cksum+=IOBUF[2];
  331.  
  332. if(cmd==0) cmd=IOBUF[3];                            /* unknown command expected          */
  333.  
  334. if(cksum==tempsum && cmd!=IOBUF[3]) return 0;
  335.  
  336. {if(cksum==tempsum && cmd==IOBUF[3]){
  337.     a_putc(ACK,P);
  338.     return IOBUF[3];}                            /* block OK returning cmd received   */
  339.  else{
  340.     a_putc(NAK,P);                                /* block not OK                      */
  341.     return 0;}}
  342. }
  343.  
  344.  
  345. int rdb(cmd,blk)                                /* receive data block                 */
  346. int cmd;                                        /* expected reply command             */
  347. unsigned char *blk;                                /* fills blk with data chars received */
  348. {                                            /* returns 0 if cannot verify block on TRY attempts */
  349. long cksum,tempsum;
  350. int i;
  351. int tmp,charcount;
  352.  
  353. for(i=0;i<6;i++){                                /* get first 6 characters         */
  354.     tmp=agetc();
  355.     if(tmp<0)    return -1;
  356.     IOBUF[i]=tmp;}
  357.  
  358. charcount=(IOBUF[4]*255)+IOBUF[5];                    /* get remaining data characters  */
  359. if(charcount){
  360.     for(i=6;i<charcount+6;i++){
  361.         tmp=agetc();
  362.         if(tmp<0)    return -1;                    /* no carrier or timeout          */
  363.         IOBUF[i]=tmp;
  364.         blk[i-6]=tmp;}}
  365.  
  366. for(tempsum=0,i=3;i<charcount+6;i++)                 /* create checksum of chars received */
  367.     tempsum+=IOBUF[i];
  368.  
  369. cksum=(long)IOBUF[0]*65025;                        /* create cheksum sent with data     */
  370. cksum+=(long)IOBUF[1]*255;
  371. cksum+=IOBUF[2];
  372.  
  373. if(cmd==0) cmd=IOBUF[3];                            /* unknown command expected          */
  374.  
  375. if(cksum==tempsum && cmd!=IOBUF[3]) return 0;
  376.  
  377. {if(cksum==tempsum && cmd==IOBUF[3]){
  378.     a_putc(ACK,P);
  379.     return charcount;}                            /* block OK returning cmd received   */
  380.  else{
  381.     a_putc(NAK,P);                                /* block not OK                      */
  382.     return -1;}}
  383. }
  384.  
  385.  
  386. int create_local_file(filespec)
  387. char *filespec;
  388. {
  389. FILE *fp;
  390. int charcount,i,try;
  391. long size=0;
  392.  
  393. strcpy(TEMP,"Creating local file: ");
  394. strcat(TEMP,filespec);
  395. report(TEMP);
  396.  
  397.  
  398. if((fp=fopen(filespec,"wb"))==NULL){                /* open the file */
  399.     strcpy(TEMP,"ERROR- Unable to create file");
  400.     report(TEMP);
  401.     scb(EM,strlen(TEMP),TEMP);
  402.     return 1;}
  403.  
  404. if(!scb(IFS,0,NULL)){                            /* start sending now */
  405.     report("ERROR- Host unable to verify IFS transmission");
  406.     fclose(fp);
  407.     return 1;}
  408.  
  409. try=1;
  410. do{
  411.     charcount=rdb(SDB,BUF);
  412.     if(OFFLINE){
  413.         fclose(fp);
  414.         report("ERROR- file transfer aborted (connection lost)");
  415.         return 1;}                            /* no carrier */
  416.     if(++try>TRY && charcount<0){
  417.         fclose(fp);
  418.         report("ERROR- file transfer aborted (receiving error)");
  419.         return 1;}
  420.     if(charcount){
  421.         try=1;
  422.         for(i=0;i<charcount;i++){
  423.             if(ferror(fp)){
  424.                 fclose(fp);
  425.                 report("ERROR- File transfer aborted (I/O error)");
  426.                 return 1;}
  427.             fputc(BUF[i],fp);}}
  428. size+=charcount;
  429. }while(charcount);                                /* stop when you rec. an empty block */
  430.  
  431. i=ferror(fp);
  432. fclose(fp);
  433. return i;                                        /* non zero equals error condition */
  434. }
  435.  
  436.  
  437. void error_message(msg)
  438. char *msg;
  439. {
  440. if(strlen(msg)>2) strcpy(TEMP,"Remote: ");
  441.  else strcpy(TEMP," ");
  442. strcat(TEMP,msg);
  443. report(TEMP);
  444.  
  445. }
  446.  
  447.  
  448. void delete_files(filespec,hostflag)
  449. char *filespec;
  450. int hostflag;                                    /* set to 0 if deleting a file while in guest mode */
  451. {
  452. int i;
  453.  
  454. strcpy(TEMP,"Deleting file(s): ");
  455. strcat(TEMP,filespec);
  456. report(TEMP);
  457.  
  458. strcpy(PATH,filespec);                            /* create a PATH for remove command */
  459. for(i=strlen(PATH);i>0;i--){
  460.     if(PATH[i]=='\\') break;
  461.     PATH[i]=NULL;}
  462.  
  463. if(findfirst(filespec,&F,0)){
  464.     strcpy(TEMP,"No file(s) to delete");
  465.     report(TEMP);
  466.     if(hostflag) scb(EM,strlen(TEMP)+1,TEMP);
  467.     return;}
  468.  
  469. do{
  470.  strcpy(TEMP,F.ff_name);                         /* temp used to report what files deleted */
  471.  strcpy(PATHNAME,PATH);                            /* pathname is file to remove */
  472.  strcat(PATHNAME,F.ff_name);
  473.  
  474.  {if(!remove(PATHNAME)){
  475.     for(i=0;i<14-strlen(F.ff_name);i++)
  476.         strcat(TEMP," ");
  477.     strcat(TEMP,"deleted");
  478.     report(TEMP);
  479.     if(hostflag) scb(EM,strlen(TEMP)+1,TEMP);}
  480.   else{
  481.     for(i=0;i<14-strlen(F.ff_name);i++)
  482.         strcat(TEMP," ");
  483.     strcat(TEMP,"cannot be deleted");
  484.     report(TEMP);
  485.     if(hostflag)  scb(EM,strlen(TEMP)+1,TEMP);}}
  486.  
  487. }while(!findnext(&F));
  488. }
  489.  
  490.  
  491. int send_file_request(fromto,send_OKTS_flag)            /* returns 1 if error, 0 on success */
  492. unsigned char *fromto;                        /* holds name of files to send */
  493. int send_OKTS_flag;                                     /* set to 1 if sending from guest to host */
  494. {
  495. int i,c,errflag=0;
  496. char s[15],d[15];
  497.  
  498. if(!seperate(fromto,FROM,TO,'|')){
  499.     report("Source/destination seperation error");
  500.     return 1;}
  501.  
  502. if(findfirst(FROM,&F,0)){
  503.     report("No files to send\n");
  504.     return 0;}
  505.  
  506. do{
  507. strcpy(SOURCE_PATHNAME,FROM);                        /* create a full source pathname */
  508.  
  509. for(i=strlen(SOURCE_PATHNAME);i>0;i--){
  510.     if(SOURCE_PATHNAME[i]=='\\') break;
  511.     SOURCE_PATHNAME[i]=NULL;}
  512.  
  513. strcat(SOURCE_PATHNAME,F.ff_name);
  514.  
  515. strcpy(DEST_PATHNAME,TO);                        /* create a full dest. pathname */
  516. for(i=strlen(DEST_PATHNAME);i>0;i--){
  517.     if(DEST_PATHNAME[i]=='\\') break;
  518.     DEST_PATHNAME[i]=NULL;}
  519.  
  520. strcpy(s,eight_plus_three(F.ff_name,'?'));            /* store 8+3 filename in s  */
  521.  
  522. for(c=0,i=strlen(TO)-1;i>0;i--){                    /* store 8+3 filename in d  */
  523.     if(TO[i]=='\\') break;
  524.     TEMP[c++]=TO[i];}
  525. TEMP[c]=NULL;
  526. strrev(TEMP);
  527. strcpy(d,eight_plus_three(TEMP,'@'));
  528.  
  529. for(i=0;i<8;i++){                                /* convert the * char to ? */
  530.     if(d[i]=='*'){
  531.         for(;i<8;i++)
  532.             d[i]='?';}}
  533. for(i=9;i<12;i++){
  534.     if(d[i]=='*'){
  535.         for(;i<12;i++)
  536.             d[i]='?';}}
  537.  
  538. for(i=0;i<12;i++)                                /* lay s on d  */
  539.     if(d[i]!='@') if(s[i]!='?' && d[i]=='?') d[i]=s[i];
  540.  
  541. for(i=0;i<12;i++)                                /* remove trash */
  542.     if(d[i]=='@' || d[i]=='?') d[i]=' ';
  543.  
  544. for(i=0,c=0;i<12;i++)                            /* remove spaces */
  545.     if(d[i]!=' ') TEMP[c++]=d[i];
  546. TEMP[c]=NULL;
  547.  
  548. strcat(DEST_PATHNAME,TEMP);                        /* add to filename to path */
  549. strupr(DEST_PATHNAME);
  550.  
  551. errflag=initiate_file_send(SOURCE_PATHNAME,DEST_PATHNAME); /* send the file */
  552. if(send_OKTS_flag) if(!rcb(OKTS,BUF)) rcb(OKTS,BUF);
  553.  
  554. }while(!findnext(&F) && !errflag);
  555. return errflag;
  556. }
  557.  
  558.  
  559. int initiate_file_send(from,to)                    /* returns 1 on error, 0 if OK */
  560. char *from,*to;
  561. {
  562. long sent=0;
  563. int i;
  564. FILE *fp;
  565.  
  566. if(findfirst(from,&F1,0)){
  567.     report("Error reading filesize from directory");
  568.     return 1;}
  569.  
  570. strcpy(TEMP,"Dest: ");
  571. strcat(TEMP,to);
  572. report(TEMP);
  573.  
  574. scb(IFR,strlen(to)+1,to);                        /* send null terminated pathname */
  575.  
  576. if(!rcb(IFS,TEMP)){                                /* OK to send file?              */
  577.     report("Error creating remote file");
  578.     return 1;}
  579.  
  580. if((fp=fopen(from,"rb"))==NULL){
  581.     strcpy(TEMP,"Unable to read file: ");
  582.     strcat(TEMP,from);
  583.     report(TEMP);
  584.     return 1;}
  585.  
  586. do{
  587.     for(i=0;i<512;i++){
  588.         if(feof(fp) || ferror(fp)) break;
  589.         sent++;
  590.         BUF[i]=fgetc(fp);}
  591.     if(feof(fp) || ferror(fp)){
  592.         sent--;
  593.         if(i) i--;}                            /* don't send an extra character */
  594.     if(!scb(SDB,i,BUF)){
  595.         strcpy(TEMP,"Unable to verify SDB transmission");
  596.         scb(EM,strlen(TEMP)+1,TEMP);
  597.         fclose(fp);
  598.         report(TEMP);
  599.         return 1;}
  600.  
  601. }while(i);
  602.  
  603. if(ferror(fp)){
  604.     strcpy(TEMP,"ERROR- reading file");
  605.     report(TEMP);
  606.     scb(EM,strlen(TEMP)+1,TEMP);}
  607.  
  608. fclose(fp);
  609. return 0;
  610. }
  611.  
  612.  
  613. int load_data(void)
  614. {
  615. FILE *fp;
  616. if((fp=fopen(DATAFILE,"r"))==NULL){
  617.     cprintf("\n\rUnable to open configuration file %s\n\r",DATAFILE);
  618.     perror("Reason");
  619.     cprintf("\n\rRun CONFIGUR to create a new config file.\n\r");
  620.     beep(3,400);
  621.     exit(1);}
  622.  
  623.  else{
  624.     fread(&BAUD,sizeof(BAUD),1,fp);
  625.     fread(&COMM,sizeof(COMM),1,fp);
  626.     fread(&RINGS,sizeof(RINGS),1,fp);
  627.     fread(&SCREENFLAG,sizeof(SCREENFLAG),1,fp);
  628.     fread(&LOGFILEFLAG,sizeof(LOGFILEFLAG),1,fp);
  629.     fread(&LOGFILE,sizeof(LOGFILE),1,fp);
  630.     fread(&FLAGFILEFLAG,sizeof(FLAGFILEFLAG),1,fp);
  631.     fread(&FLAGFILE,sizeof(FLAGFILE),1,fp);
  632.     fread(&PASSWORD,sizeof(PASSWORD),1,fp);
  633.     fread(&WAITING,sizeof(WAITING),1,fp);
  634.     fclose(fp);}
  635.  
  636. return 1;
  637. }
  638.  
  639.  
  640. void copyright(void)
  641. {
  642. system("cls");
  643. textbackground(BLACK);
  644. textcolor(LIGHTCYAN);
  645. empty_box(20,8,65,14);
  646. gotoxy(29,10);
  647. cprintf("H-SEND File Transfer System");
  648. gotoxy(22,12);
  649. cprintf("(C) John Hutchey 1991  All Rights Reserved");
  650. }
  651.  
  652.  
  653. void beep(loop,freq)
  654. int loop,freq;
  655. {
  656. int i;
  657. unsigned char p;
  658. long timer;
  659.  
  660. union{
  661.     long divisor;
  662.     unsigned char c[2];
  663.     }count;
  664.  
  665. for(i=0;i<loop;i++){
  666.     count.divisor=1193280/freq;
  667.     outportb(67,182);
  668.     outportb(66,count.c[0]);
  669.     outportb(66,count.c[1]);
  670.     p=inportb(97);
  671.     outportb(97,p|3);
  672.  
  673.     timer=biostime(0,0);
  674.     while(biostime(0,0)-timer<3);
  675.  
  676.     outportb(97,p);
  677.  
  678.     timer=biostime(0,0);
  679.     while(biostime(0,0)-timer<1);}
  680. }
  681.  
  682.  
  683. int seperate(combined,first,second,seperator)
  684. char *combined,*first,*second,seperator;
  685. {
  686. int i,c;
  687.  
  688. for(i=0;i<strlen(combined);i++)
  689.     if(combined[i]==seperator) break;
  690. if(i==strlen(combined)) return 0;                    /* no seperator present in string */
  691.  
  692. for(i=0;i<strlen(combined);i++){
  693.     if(combined[i]==seperator) break;
  694.     first[i]=combined[i];}
  695. first[i]=NULL;                                    /* first half of *combined copied to *first */
  696.  
  697. for(i++,c=0;i<=strlen(combined);i++)
  698.     second[c++]=combined[i];                        /* second half of *combined copied to *second */
  699.  
  700. return 1;                                        /* OK */
  701. }
  702.  
  703.  
  704. char *eight_plus_three(source,fill)
  705. char *source;
  706. char fill;
  707. {
  708. static char a[15];
  709. char b[5];
  710. char filler[2];
  711.  
  712. filler[0]=fill;
  713. filler[1]=NULL;
  714.  
  715. if(!seperate(source,a,b,'.')){
  716.     strcpy(a,source);
  717.     b[0]=NULL;}
  718.  
  719. while(strlen(a)<8) strcat(a,filler);                /* pad to 8 chars */
  720. strcat(a,".");                                    /* add a period   */
  721. strcat(a,b);                                    /* add extension  */
  722. while(strlen(a)<12) strcat(a,filler);                /* pad to 12 chars */
  723. return a;                                        /* return pointer to converted string */
  724. }
  725.  
  726.  
  727. void tsr(size)                        /* terminate and stay resident enable */
  728. unsigned int size;
  729. {
  730. union REGS r;
  731.  
  732. r.h.ah=49;
  733. r.h.al=0;
  734. r.x.dx=size;
  735. int86(0x21,&r,&r);
  736. }
  737.  
  738.  
  739. void empty_box(start_x,start_y,end_x,end_y)
  740. int start_x,start_y,end_x,end_y;
  741. {
  742. int x,y;
  743.  
  744.                                             /* set up corners */
  745. gotoxy(start_x,start_y);
  746. cprintf("%c",201);
  747. gotoxy(end_x,start_y);
  748. cprintf("%c",187);
  749. gotoxy(start_x,end_y);
  750. cprintf("%c",200);
  751. gotoxy(end_x,end_y);
  752. cprintf("%c",188);
  753.  
  754.                                             /* top & bottom line */
  755. for(x=start_x+1;x<end_x;x++){
  756.     gotoxy(x,start_y);
  757.     cprintf("%c",205);
  758.     gotoxy(x,end_y);
  759.     cprintf("%c",205);}
  760.  
  761.                                             /* side lines */
  762. for(y=start_y+1;y<end_y;y++){
  763.     gotoxy(start_x,y);
  764.     cprintf("%c",186);
  765.     gotoxy(end_x,y);
  766.     cprintf("%c",186);}
  767.  
  768. }
  769.  
  770.  
  771. void b_sleep(seconds)                    /* replaces standard sleep function */
  772. {
  773. long timer;
  774.  
  775. timer=biostime(0,0);
  776. while(biostime(0,0)-timer<seconds*18);
  777. }
  778.